<template>
	<view class="page">
		
<!-- 		<uni-forms class="form" ref="form" :modelValue="formData" :rules="rules">
			<uni-forms-item label="姓名" name="name" required>
				<uni-easyinput class="input" type="text" v-model="formData.name" placeholder="请输入姓名" :adjust-position="false"/>
			</uni-forms-item>
			<uni-forms-item label="手机号" name="phone" required>
				<uni-easyinput class="input" v-model="formData.phone" type="text" placeholder="请输入手机号" :adjust-position="false"/>
			</uni-forms-item>
			<uni-forms-item label="身份证号" name="idcard" required>
				<uni-easyinput class="input" v-model="formData.idcard" type="text" placeholder="请输入身份证号" :adjust-position="false"/>
			</uni-forms-item>
		</uni-forms> -->
		<view class="tipContend" v-html="tipContend"></view>
		<view class="btnBox"  @click="submit">立即申请</view>
		<uni-popup ref="popupSuccess" type="message">
			<uni-popup-message :type="type" :message="title" :duration="2000"></uni-popup-message>
		</uni-popup>
	</view>
</template>
<script>
		import {ShopCarInfosave,findtipinfobytipid} from "../../common/api.js"
export default {
	data() {
		return {
			type:'',
			title:'',
			actype:'chouzg',
			currUser:'',
			tipContend:'',
			// 表单数据
			formData: {
				name: '',
				phone: '',
				idcard:''
			},
			// rules: {
			// 	name: {
			// 		rules: [{
			// 				required: true,
			// 				errorMessage: '请输入姓名',
			// 			},
			// 			{
			// 				minLength: 2,
			// 				errorMessage: '姓名长度最少{minLength}个字符',
			// 			}
			// 		]
			// 	},
			// 	phone: {
			// 		rules: [{
			// 			required: true,
			// 			errorMessage: '请输入手机号',
			// 		},
			// 		 {
			// 		                                validateFunction: function(rule, value, data, callback) {
			// 											let rep=/^1[3|4|5|6|7|8|9][0-9]\d{8}$/
			// 		                                    if (!rep.test(value)) {
			// 		                                        callback('请输入正确的手机号码')
			// 		                                    }
			// 		                                    return true
			// 		                                }
			// 		                            }
			// 		]
			// 	}
			// }
		}
	},
	onLoad(option){
		this.currUser = uni.getStorageSync('currUser')
		this.actype=option.type
		findtipinfobytipid({tipid:this.actype}).then(res=>{
			let data=res.extend.TipInfo.tipContend
			this.tipContend=this.repairRichText(data)
		})
	},
	methods: {
		repairRichText(html) {
						// 去掉<img>中style /width / height属性
						let newContent = html.replace(/<img[^>]*>/gi, (match) => {
							match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '')
							match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '')
							match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '')
							match = match.replace(/style\s*=\s*(["'])(?:(?!\1).)*\1/gi, '') // 去除 style=""这样的属性
							return match
						})
						// 修改所有style里的width属性为max-width:100%
						newContent = newContent.replace(/style="[^"]+"/gi, (match) => {
							match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
								'max-width:100%;')
							return match
						})
		 
						// 去掉所有<br/>标签
						newContent = newContent.replace(/<br[^>]*\/>/gi, '')
						// img标签添加style属性：max-width:100%;height:auto
						newContent = newContent.replace(/\<img/gi,
							'<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
						)
						return newContent;
		},
		submit() {
				
			// this.$refs.form.validate().then(res=>{
			// 	console.log('表单数据信息：', res);
			// }).catch(err =>{
			// 	console.log('表单错误信息：', err);
			// })
			let form={
				userid:this.currUser.userid,
				actype:'chouzg'
			}
			ShopCarInfosave(form).then(res=>{
				this.type="success"
				this.title=res.extend.MSG
					this.$refs.popupSuccess.open()
				
			}).catch(err=>{
				this.type="success"
				this.title=err.data.extend.MSG
					this.$refs.popupSuccess.open()
			})
		}
	}
}
</script>
<style scope lang="scss">
	.page{
		padding:30rpx;
		background:#fff;
	}
	.form{
		background:#fff;
	}
	.btnBox{
		background:#ea6011;
		color:#fff;
		font-size:14px;
		width:60%;
		margin-left:20%;
		border-radius:10px;
		line-height:30px;
		text-align:center;
	}
	.tipContend{
		width:100%;
		overflow: auto;
	}
	</style>